package com.ruoyi.web.controller.market.member;

import java.util.List;
import java.util.Map;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.db.domain.MemberFeedback;
import com.ruoyi.member.service.IMemberFeedbackService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.web.wapper.MemberFeedbackWapper;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 用户反馈Controller
 * 
 * @author ruoyi
 * @date 2022-08-23
 */
@Controller
@RequestMapping("/member/feedback")
public class MemberFeedbackController extends BaseController
{
    private String prefix = "member/feedback";

    @Autowired
    private IMemberFeedbackService memberFeedbackService;

    @RequiresPermissions("member:feedback:view")
    @GetMapping()
    public String feedback()
    {
        return prefix + "/feedback";
    }

    /**
     * 查询用户反馈列表
     */
    @RequiresPermissions("member:feedback:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(MemberFeedback memberFeedback)
    {
        startPage();
        List<Map<String, Object>> mapList = memberFeedbackService.selectMemberFeedbackListMap(memberFeedback);
        mapList = new MemberFeedbackWapper(mapList).wrap();
        return getDataTable(mapList);
    }

    /**
     * 导出用户反馈列表
     */
    @RequiresPermissions("member:feedback:export")
    @Log(title = "用户反馈", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(MemberFeedback memberFeedback)
    {
        List<MemberFeedback> list = memberFeedbackService.selectMemberFeedbackList(memberFeedback);
        ExcelUtil<MemberFeedback> util = new ExcelUtil<MemberFeedback>(MemberFeedback.class);
        return util.exportExcel(list, "用户反馈数据");
    }

    /**
     * 新增用户反馈
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存用户反馈
     */
    @RequiresPermissions("member:feedback:add")
    @Log(title = "用户反馈", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(MemberFeedback memberFeedback)
    {
        return toAjax(memberFeedbackService.insertMemberFeedback(memberFeedback));
    }

    /**
     * 修改用户反馈
     */
    @RequiresPermissions("member:feedback:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        MemberFeedback memberFeedback = memberFeedbackService.selectMemberFeedbackById(id);
        mmap.put("memberFeedback", memberFeedback);
        return prefix + "/edit";
    }

    /**
     * 修改保存用户反馈
     */
    @RequiresPermissions("member:feedback:edit")
    @Log(title = "用户反馈", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(MemberFeedback memberFeedback)
    {
        return toAjax(memberFeedbackService.updateMemberFeedback(memberFeedback));
    }

    /**
     * 删除用户反馈
     */
    @RequiresPermissions("member:feedback:remove")
    @Log(title = "用户反馈", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(memberFeedbackService.deleteMemberFeedbackByIds(ids));
    }
}
